﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynCMS.NET.Core.Entities.Configuration
{
    /// <summary>
    /// Name/value pair for one configuration setting
    /// </summary>
    public class Setting : Base.PersistableEntity
    {
        public enum SettingValueType
        {
            Text = 0,
            Boolean = 1,
            Integer = 2,
            Number = 3,
            Datetime = 4
        }

        public enum SettingNames
        {
            CaseSensitive
        }

        /// <summary>
        /// Containing set of settings
        /// </summary>
        public Set Set { get; set; }

        /// <summary>
        /// Setting name
        /// </summary>
        public string Name { get; set; }

        public SettingNames SettingName
        {
            get
            {
                return (SettingNames)Enum.Parse(typeof(SettingNames), this.Name);
            }
            set
            {
                this.Name = Enum.GetName(typeof(SettingNames), value);
            }
        }

        /// <summary>
        /// Setting value
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// Type of setting value
        /// </summary>
        public SettingValueType Type
        {
            get
            {
                return (SettingValueType)this.TypeValue;
            }
            set
            {
                this.TypeValue = (int)value;
            }
        }

        public int TypeValue { get; set; }

        IFormatProvider NumberFormat = System.Globalization.NumberFormatInfo.InvariantInfo;

        public decimal GetDecimalValue()
        {
            return decimal.Parse(this.Value, NumberFormat);
        }

        public void SetDecimalValue(decimal value)
        {
            this.Value = value.ToString(NumberFormat);
        }
    }
}